/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		mask.hpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-03-24 02:02
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-08-04 01:24
*
*   Description:
*
=============================================================================*/
#ifndef MASK_H
#define MASK_H

#include "../shape/shape_interface.hpp"
#include <boost/property_tree/ptree.hpp>

namespace geoxfem {
namespace geometry {

struct circle {};

template <typename MaskPolicy>
struct MeshMask {
  using ptree = boost::property_tree::ptree;
  MeshMask(const VectorXR& centre, const ptree& data)
      : m_centre{centre}, m_data(data) {}

  template <typename DimensionType, typename degree>
  bool operator()(const ShapeInterface<DimensionType, degree>& shp) const {
    for(auto& p : pointsIn(shp))
      if(*this(p))
        return true;
    return false;
  }
  template <size_t dim>
  bool operator()(const Point<dim>&) const {
    return false;
  }

private:
  VectorXR m_centre;
  ptree    m_data;
};

template <>
template <size_t dim>
bool MeshMask<circle>::operator()(const Point<dim>& point) const {
  _real      r = m_data.get<_real>("radius");
  Point<dim> pc(m_centre);
  return boost::geometry::comparable_distance(pc, point) < r * r;
}

}  // namespace geometry
}  // namespace geoxfem

#endif /* MASK_H */
